package org.example.service.simple;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.stream.IntStream;

/**
 * @author Tang
 * @classname SimpleSender
 * @description [  ]
 * @date 2023/4/10 21:29
 */
//@Component
public class SimpleSender implements CommandLineRunner {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public void run(String... args) throws Exception {

        final Message message = MessageBuilder
                .withBody("hello world!".getBytes(StandardCharsets.UTF_8))
                .setContentType(MessageProperties.CONTENT_TYPE_BYTES)
                .setMessageId(UUID.randomUUID().toString())
                .build();

        IntStream.range(0,10)
                 .forEach(i -> rabbitTemplate.send("ex.tang.test01",message));
    }

}
